<!--
描述：慕课模块-课程审核
开发人：zhaohang
开发日期：2019年11月7日
-->
<template lang="pug">
  kalix-dialog.user-add(title='推荐' bizKey="moocClass" ref="kalixBizDialog" v-bind:formModel.sync="formModel"
  v-bind:targetURL="targetURL"  :submitCustom="submitCustom")
      div.el-form(slot="dialogFormSlot")
        el-form-item(label="推荐" prop="recommend" v-bind:rules="rules.recommend" width="80")
          el-select(v-model="formModel.recommend"  placeholder="请选择")
            el-option(v-for="item in option" v-bind:key="item.value" v-bind:value="item.value" v-bind:label="item.label")
</template>


<script type="text/ecmascript-6">
  import {moocClassURL} from '../../config.toml'
  import FormModel from './model'
  import Message from '../../../../../common/message'
  import EventBus from '../../../../../components/corelib/common/eventbus'
  import {ON_REFRESH_DATA} from '../../../../../components/corelib/components/common/event.toml'

  export default {
    name: 'moocClassRecommend',
    data() {
      return {
        temp: null,
        fileList: [],
        formModel: Object.assign({}, FormModel),
        option: [{
          value: '是',
          label: '是'
        }, {
          value: '否',
          label: '否'
        }
        ],
        labelWidth: '120px',
        targetURL: moocClassURL,
        rules: {
          recommend: [{required: true, message: '请选择', trigger: 'change'}]
        }
      }
    },
    methods: {
      dataFormat(val) {
        let d = new Date(val)
        return this.$M_FormatDate(d, 'yyyy-MM-dd')
      },
      submitCustom(baseDialog) { // 提交
        if (baseDialog.formModel.appraise === '否') {
          this.formModel.appraise = 'false'
        } else {
          this.formModel.appraise = 'true'
        }
        if (baseDialog.formModel.charge === '否') {
          this.formModel.charge = 'false'
        } else {
          this.formModel.charge = 'true'
        }
        if (baseDialog.formModel.isOpen === '通过') {
          this.formModel.isOpen = 1
        } else {
          this.formModel.isOpen = 2
        }
        console.log('-------------', baseDialog.formModel.recommend)
        if (baseDialog.formModel.recommend === '是') {
          this.formModel.recommend = true
        } else {
          this.formModel.recommend = false
        }
        this.axios.request({
          method: 'PUT',
          url: moocClassURL + '/' + this.formModel.id,
          data: {
            id: this.formModel.id,
            className: this.formModel.className,
            classIntroduce: this.formModel.classIntroduce,
            teacherIntroduce: this.formModel.teacherIntroduce,
            classCover: this.formModel.classCover,
            departmentId: this.formModel.departmentId,
            specialityId: this.formModel.specialityId,
            classTypeId: this.formModel.classTypeId,
            isOpen: this.formModel.isOpen,
            appraise: this.formModel.appraise,
            charge: this.formModel.charge,
            openTime: this.formModel.openTime,
            browseNum: this.formModel.browseNum,
            reason: this.formModel.reason,
            teacherId: this.formModel.teacherId,
            recommend: this.formModel.recommend
          }
        }).then(response => {
          if (response.data.success) {
            Message.success(response.data.msg)
            EventBus.$emit('moocClass' + '-' + 'KalixDialogClose')
          } else {
            Message.error(response.data.msg)
            EventBus.$emit('moocClass' + '-' + 'KalixDialogClose')
          }
          // 刷新列表
          console.log(' ===== BaseDialog ON_REFRESH_DATA ===== ', ON_REFRESH_DATA)
          EventBus.$emit(ON_REFRESH_DATA, 'moocClass')
          console.log('[kalix] dialog submit button clicked !')
        })
      }
    }
  }
</script>

<style scoped lang="stylus" type="text/stylus">


</style>
